#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

class Solution
{
public:
    void reverse(string &a)
    {
        auto begin = a.begin();
        auto end = a.end() - 1;
        while (begin < end)
        {
            swap(*begin, *end);
            begin++;
            end--;
        }
    }
    string addStrings(string num1, string num2)
    {
        string c;
        int flag = 0;
        reverse(num1);
        reverse(num2);
        for (int i = 0; i < num1.size() || i < num2.size(); ++i)
        {
            if (i < num1.size())
            {
                flag += num1[i] - '0';
            }
            if (i < num2.size())
            {
                flag += num2[i] - '0';
            }
            c += flag % 10 + '0';
            flag /= 10;
        }
        if (flag)
        {
            c += '1';
        }
        reverse(c);
        return c;
    }
};

